const app = getApp();
var config = app.globalData.config;
const http = require('../../utils/http.js');
Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		index: 0,
		schoolList: [],
		schoolIdDauflt: 0, //初始化校园id
		classList: [],
		_url: config.imageUrl

	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onReady: function() {
		if (!app.login()) {
			return;
		}
	},
	onLoad(options) {
		this.getSchoolList();
	},
	getSchoolList() { //获取【校园列表】
		var that = this;
		http.httpPost(config.get_school_list, {

		}, function(e) {
			that.schoolList = e.data;
			that.setData({
				'schoolList': e.data
			})
			//
			if (e.data.length > 0) {
				that.schoolIdDauflt = e.data[0].id;
				that.getClassList()
			}

		});

	},
	//选择学校
	schoolChange: function(e) {
		this.setData({
			index: e.detail.value
		});

		this.schoolIdDauflt = this.schoolList[e.detail.value].id;
		this.getClassList();
	},
	getClassList() { //获取【报名课程】
		var that = this;
		http.httpPost(config.get_classes_list, {
			school_id: that.schoolIdDauflt
		}, function(e) {
			that.classList = e.data;

			that.setData({
				'classList': e.data
			})

		});
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})
